<?php
ob_start();
session_cache_expire(999999999);
if (!isset($_SESSION)) {
    session_start();
}
$lang = $_SESSION['lang'];
if ($lang == '')
    $lang = 'EN';
if (!isset($_REQUEST['page'])) {
    $page = 1;
} else {
    $page = $_REQUEST['page'];
}
$rows_per_page = $_SESSION['rows_page'];
$page_start = ( $page - 1 ) * $rows_per_page;
$page_end = $page * $rows_per_page;

include("operations/get_lang.php");
$value = getlang();
include($value);

if($_SESSION['role']!=2){
	echo $_SESSION['role'];
	header("Location: ../index.php");
}
include 'operations/connection.php';

if (isset($_REQUEST['delete'])) {
    $mxoa = $_REQUEST['xoa'];
    for ($i = 0; $i < count($mxoa); $i++) {
        $xoa = explode('-', $mxoa[$i]);
        if ($xoa[1] == 13 || $xoa[1] == 15) {
            mysql_query("delete from buying_document where buying_document.document_id='" . $xoa[0] . "'");
        } else {
            mysql_query("delete from ap_advance where ap_advance.document_id='" . $xoa[0] . "'");
        }
        mysql_query("delete from approvedoc  WHERE IDApproveDoc='" . $xoa[0] . "'");
    }
}

if (isset($_REQUEST['deleteMySending'])) {
    $_SESSION['chomaychet'] = "";
    $mxoa = $_REQUEST['xoa'];
    if (count($mxoa) > 0) {
        for ($i = 0; $i < count($mxoa); $i++) {
            $xoa = explode('-', $mxoa[$i]);
            $result = mysql_query("select listapprove.ID FROM listapprove WHERE IDGroupApprove='" . $xoa[1] . "' and (IDStatus = 1 or IDStatus = 3 or IDStatus > 9)");
            if (mysql_num_rows($result) == 0) {
                mysql_query("delete from listapprove where listapprove.IDGroupApprove='" . $xoa[1] . "'");
                mysql_query("delete from list_reference where list_reference.id_group='" . $xoa[1] . "'");
                if ($xoa[2] == 13 || $xoa[2] == 15) {
                    mysql_query("delete from buying_document where buying_document.document_id='" . $xoa[0] . "'");
                } else if ($xoa[2] == 17) {
                    mysql_query("delete from ap_advance where ap_advance.document_id='" . $xoa[0] . "'");
                }
                mysql_query("delete from approvedoc  WHERE IDApproveDoc='" . $xoa[0] . "'");
            } else {
                if ($_SESSION['chomaychet'] == "") {
                    $_SESSION['chomaychet'] = $l_tbnodelete_mysending . " " . $xoa[3];
                } else {
                    $_SESSION['chomaychet'].="\\n" . $xoa[3];
                }
            }
        }
    } else {
        $_SESSION['chomaychet'] = $l_nochoose;
    }
}

if (isset($_REQUEST['updateMyDecl']) || isset($_REQUEST['updateMyMeeting']) || isset($_REQUEST['updateMyApp'])) {
    $xoa = $_REQUEST['xoa'];
    for ($i = 0; $i < count($xoa); $i++) {

        //$sql="UPDATE approvedoc SET IDStatus='6' WHERE IDApproveDoc='".$xoa[$i]."' AND isView=1";
        $sql = "UPDATE approvedoc SET IDStatus='6' WHERE IDApproveDoc='" . $xoa[$i] . "'";
        //echo $sql;
        mysql_query($sql);
    }
}

$value = getlang();
include($value);

$content = "content/list-mydocument-sending-content.php";
if (isset($_REQUEST['content'])) {

    $content = "content/" . $_REQUEST['content'] . ".php";
}
if (isset($_REQUEST['action']))
    $action = $_REQUEST['action'];
if (isset($_REQUEST['id']))
    $id = $_REQUEST['id'];

if (isset($_REQUEST['type'])) {
    $type = $_REQUEST['type'];

    if ($type == 7)
        $content = 'content/view-form7-content.php';
    else if ($type == 12)
        $content = 'content/view-form12-content.php';
    else if ($type == 13)
        $content = 'content/view-form13-content.php';
    else if ($type == 15)
        $content = 'content/view-form15-content.php';
    else if ($type == 14)
        $content = 'content/view-form14-content.php';
    else if ($type == 16)
        $content = 'content/view-form16-content.php';
    else if ($type == 17)
        $content = 'content/view-form17-content.php';
    else if ($type == 18)
        $content = 'content/view-form18-content.php';
    else if ($type == 19)
        $content = 'content/view-form19-content.php';
    else if ($type == 11)
        $content = 'content/view-form11-content.php';
    
	if ($_SESSION['action'] == "my_declined" || $_SESSION['action'] == "my_approved") {
	    mysql_query("UPDATE approvedoc SET isView='1' WHERE (IDApproveDoc='$id')");
	}
}


if (!isset($_SESSION['user'])) {
    header('Location: login.php?timeout=on');
} else {
    $username = $_SESSION['fullname'];
    $id_employee = $_SESSION['IDEmployee'];
}
echo $_SESSION['back'];

$title = $_SESSION['browser'];




if ($_SESSION['role'] == 1) {

    require("MainTemplateAdmin.php");
} else {
    require("MainTemplate.php");
}
ob_flush();
?>